import { createStore } from 'vuex';

const store = createStore({
  state: {
    userName: null,  // 当前用户的用户名
    id: null,  // 当前用户的 ID
    userType: null,  // 当前用户的角色
  },
  mutations: {
    SET_ROLE(state, payload) {
      state.userType = payload.curUserType;
      state.id = payload.curId;
      state.userName = payload.curUsername;
    },
    setUserRole(state, payload) {
      state.userType = payload.curUserType;
      state.id = payload.curId;
      state.userName = payload.curUsername;
    },
  },
  getters: {
    userIsLoggedIn: state => !!state.id,  // 如果用户的 ID 不是 null，则用户已登录
    userType: state => state.userType,  // 获取用户类型
  },
});

export default store;
